<?php

class MemberForm extends CFormModel {
	
	public $account_name;
	public $newPassword;
	public $reNewPassword;
	
	protected $_member = null;
	
	public function rules() {
		return array(
			array('newPassword, reNewPassword', 'required'),
			array('account_name','rename'),
			array('newPassword','length','min'=>6),
			array('reNewPassword', 'compare', 'compareAttribute'=>'newPassword')
		);
	}
	public function rename($attribute,$params){
		if(empty($this->member)){
			$this->addError('account_name','用户名不正确');
		}else{
			return true;
		}
		
	}
	
	
	public function attributeNames() {
		return array(
			'newPassword',
			'reNewPassword',
			'account_name',
		);
	}
	
	public function attributeLabels() {
		return array(
			'newPassword' => '新密码',
			'reNewPassword' => '确认新密码',
			'account_name'=>'用户名',
		);
	}

	public function save() {
		if($this->validate()) {
			$this->member->worker_password = $this->newPassword;
			return $this->member->save();
		} else {
			return false;
		}
	}
	
	protected function getMember() {
		if(!$this->_member) {
			$this->_member = MemberAccount::model()->findByAttributes(array('worker_name'=>$this->account_name));
		}
		return $this->_member;
	}
}

?>